<template>
    <div>
        <!-- 修改物流弹窗 -->
        <el-dialog :title="type == 1 ? '填写物流信息' : '修改物流信息'" :visible.sync="dialogShow" width="450px" top="30vh">
            <el-form 
                :model="editFormLog" 
                label-width="120px" 
                ref="editLogForm"
                @keyup.enter.native="submitEditForm('editLogForm')" 
                :rules="ruleLog">
                <el-form-item label="物流公司" prop="logCompany">
                    <el-input v-model="editFormLog.logCompany" class="dialogInput" placeholder="请输入物流公司" autofocus></el-input>
                </el-form-item>
                <el-form-item label="快递单号" prop="logNum">
                    <el-input v-model="editFormLog.logNum" class="dialogInput" placeholder="请输入快递单号"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogShow = false">取 消</el-button>
                <el-button type="primary" @click="submitEditForm('editLogForm')">保 存</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        props:['type','editFormLog','applyId'],
        data() {
            let checkLogNum = (rule, value, callback)=>{
                if(value == ''){
                    callback(new Error('请输入快递单号'));
                }
                if(!this.util.RegExpr.checkNum(value)){
                    callback(new Error('快递单号只支持数字'));
                }else{
                    callback();
                }
            }
            return {
                dialogShow : false,
                ruleLog:{
                    logCompany : [{ required: true, message: '请输入物流公司', trigger: 'blur'}],
                    logNum : [{ required: true, validator: checkLogNum, trigger: 'blur'}]
                }
            }
        },
        created(){

        },
        methods: { 
            submitEditForm(formName){
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.axiosEdit();
                    } else {
                        return false;
                    }
                });
            },
            axiosEdit(){
                //物流修改/填写接口
                this.$axios
                    .post("/admin/refund/updateRefundOrdersExpress.json",{
                        refundOrderNo : this.applyId,
                        expressCom : this.editFormLog.logCompany,
                        expressNo : this.editFormLog.logNum 
                    })
                    .then(res => {
                        const data = res.data;
                        if(data.success){
                            this.$message.success('操作成功！');
                            this.dialogShow = false;
                            this.$emit('getData',''); //更新数据
                        }else{
                            this.$message.error(data.message);
                        } 
                    })
            },
        }
    }

</script>


<style scoped>
    .dialogInput{
        width: 215px;
    }
</style>
